package com.guli.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guli.commonutils.R;
import com.guli.eduservice.bean.EduCourse;
import com.guli.eduservice.bean.EduTeacher;
import com.guli.eduservice.service.EduCourseService;
import com.guli.eduservice.service.EduTeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.scheduling.config.ContextLifecycleScheduledTaskRegistrar;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName EduTeacherController
 * @Description TODO
 * @Author YinLiangTao Email:1517535831@qq.com
 * @Date 2022/4/15 12:37
 * @Version 1.0
 */
@RestController
@RequestMapping("/eduservice/teacherFront")
@CrossOrigin
public class EduTeacherFrontController {
    @Resource
    private EduTeacherService eduTeacherService;

    @Resource
    private EduCourseService eduCourseService;

    @ApiOperation("讲师信息分页显示")
    @GetMapping("/getTeacherPage/{page}/{limit}")
    public R getTeacherPage(@PathVariable("page") long page,@PathVariable("limit")long limit){
        Page<EduTeacher> pageParam = new Page<EduTeacher>(page, limit);
        Map<String, Object> map = eduTeacherService.pageListWeb(pageParam);
        return R.ok().data(map);
    }

    @ApiOperation("获取讲师基础信息和课程")
    @GetMapping("/getTeacherInfo/{teacherId}")
    public R getTeacherInfo(@PathVariable("teacherId")String teacherId){
        EduTeacher teacher = eduTeacherService.getById(teacherId);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> list = eduCourseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("course",list);
    }
}
